// 使用Base64简单加密密码
const encryptPassword = (password) => {
  return btoa(password)
}

// 解密密码
const decryptPassword = (encrypted) => {
  return atob(encrypted)
}

export const users = [
  {
    username: 'diaoqi',
    password: encryptPassword('diaoqi'),
    role: 'admin',
    nickname: '管理员'
  },
  {
    username: 'hanyang',
    password: encryptPassword('hanyang'),
    role: 'user',
    nickname: '普通用户'
  },
  {
    username: 'reach123',
    password: encryptPassword('reach123'),
    role: 'user',
    nickname: '普通用户'
  }
]

export const validateUser = (username, password) => {
  const user = users.find(u => u.username === username)
  if (!user) return { success: false, message: '用户不存在' }
  
  if (decryptPassword(user.password) === password) {
    const { password, ...userInfo } = user
    return { success: true, userInfo }
  }
  
  return { success: false, message: '密码错误' }
}